import http from 'http'
import Koa from 'koa'
import { ENV } from './config'
import koaBody from 'koa-body'
import router from './router'
import '@/utils/ip'
import logger from '@/utils/logger'

const app = new Koa()
const server = http.createServer(app.callback())

app.use(koaBody())

app.use(router.routes())

//listen
server.listen(ENV.port, () => console.info(`\nhttp://localhost:${ENV.port}`))

logger.info('测试外部文件')

app.on('error', err => {
  logger.error('server error' + err)
})

process.on('uncaughtException', err => {
  console.error(`${err.message}\n${err.stack}`)
})

process.on('unhandledRejection', (reason, p) => {
  console.error(`Unhandled Rejection at: Promise ${p} reason: `, reason)
})
